package com.leyou.item.web;

import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecificationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * description: 规格参数相关接口
 * @author 朱正磊
 * @date 2021-04-01 13:17:45
 */
@RestController
@RequestMapping("spec")
public class SpecificationController {

    @Resource
    private SpecificationService specificationService;

    /**
     * description: 根据商品分类id查询规格参数组集合
     * @author 朱正磊
     * @date 2021-04-01 13:33:30
     * @param cid 商品分类id
     * @return 返回规格参数组集合
     */
    @GetMapping("groups/{cid}")
    public ResponseEntity<List<SpecGroup>> querySpecGroupsByCid(@PathVariable("cid") Long cid) {
        return ResponseEntity.ok(specificationService.querySpecGroupsByCid(cid));
    }

    /**
     * description: 根据商品规格参数组id或者商品分类id或者是否为搜索规格参数查询商品规格参数集合
     * @author 朱正磊
     * @date 2021-04-01 14:54:41
     * @param gid 商品规格参数组id
     * @param cid 商品分类id
     * @param searching 是否为搜索规格参数
     * @return 返回商品规格参数集合
     */
    @GetMapping("params")
    public ResponseEntity<List<SpecParam>> querySpecParams(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching) {
        return ResponseEntity.ok(specificationService.querySpecParams(gid, cid, searching));
    }

    /**
     * description: 根据商品分类id查询规格参数组以及组内规格参数
     * @author 朱正磊
     * @date 2021-04-12 00:35:44
     * @param cid 商品分类id
     * @return 返回规格参数组以及组内规格参数
     */
    @GetMapping("groups")
    public ResponseEntity<List<SpecGroup>> queryGroupsByCid(@RequestParam("cid") Long cid) {
        return ResponseEntity.ok(specificationService.queryGroupsByCid(cid));
    }

}
